package com.springapp.mvc.services;

import com.springapp.mvc.db.DAO.PersonDAO;
import com.springapp.mvc.db.entities.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PersonService {

    @Autowired
    private PersonDAO personDAO;

    public List<Person> findAll(){

        return personDAO.findAll();
    }

    public void delete(Person person){
        personDAO.delete(person);
    }

    public boolean add(String name, String age) {
        try {
            Person person = new Person();
            personDAO.add(person);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    public void deleteById(int id){
        personDAO.delete(personDAO.getById(id));
    }

}
